package com.bona.service.system;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.bona.dao.system.SysCommonDao;
import com.bona.model.system.SysConfigModel;
import com.bona.model.system.SysLogModel;
import com.bona.model.system.SysOperationModel;
import com.bona.model.system.SysSmsModel;
import com.bona.util.common.UUIDGenerator;

@Service("commonService")
@Transactional
public class SysCommonService {
	
	@Autowired
	private SysCommonDao commonDao;

	/**
	 * 获取发送消息
	 * @param model
	 * @return
	 */
	public List<SysSmsModel> querySMs(SysSmsModel model) {
		
		List<SysSmsModel> smsModels = commonDao.querySMs(model);
		return smsModels;
	}
	
	/**
	 * 通过操作码获取对象
	 * @param operationCode
	 * @return
	 */
	public SysOperationModel queryOptByCode(String operationCode) {
		
		SysOperationModel operationModel = commonDao.queryOptByCode(operationCode);
		return operationModel;
	}
	
	/**
	 * 获取所有配置信息
	 * @param name
	 * @param code
	 * @return
	 */
	public List<SysConfigModel> queryConfig() {
		
		List<SysConfigModel> sysConfigs = new ArrayList<SysConfigModel>();
		SysConfigModel sysConfigModel = commonDao.queryConfig("bb", "aa");
		sysConfigs.add(sysConfigModel);
		return sysConfigs;
	}
	
	/**
	 * 获取配置信息
	 * @param name
	 * @param code
	 * @return
	 */
	public SysConfigModel queryConfig(String name, String code) {
		
		SysConfigModel sysConfig = commonDao.queryConfig(name, code);
		return sysConfig;
	}
	
	/**
	 * 获取字典信息
	 * @param dictField
	 * @param dictText
	 * @param dictTable
	 * @return
	 */
	public List<Map<String, String>> queryDict(String dictField, String dictText, String dictTable) {
		
		List<Map<String, String>> dictList = commonDao.queryDict(dictField, dictText, dictTable);
		return dictList;
	}
	
	/**
	 * 添加日志信息
	 * @param model
	 * @throws Exception
	 */
	public Integer addLog(SysLogModel model) {
		model.setId(UUIDGenerator.generate());
		model.setOperatetime(new Date());
		return commonDao.addLog(model);
	}
	
	/**
	 * 编辑页面检查字段是否重复
	 * @param tableName
	 * @param fieldName
	 * @param fieldValue
	 * @param rowId
	 * @return
	 */
	public Integer queryEditDumplicate(String tableName, String fieldName, String fieldValue, String rowId) {
		
		return commonDao.queryEditDumplicate(tableName, fieldName, fieldValue, rowId);
	}
	
	/**
	 * 通过iconId获取关联的菜单功能数量
	 * @param iconId
	 * @return
	 */
	public Integer queryFunctionCountByIconId(String iconId) {
		return commonDao.queryFunctionCountByIconId(iconId);
	}
	
}
